﻿@{
    Layout = null;
}

<div>
    <div class="input-group">
        <div class="col-3 pr-0" style="display: none">
            <label id="SAMPLE-AddRetentionConfig-RetentionConfigId">@ViewData["RetentionConfigId"]</label>
            <label id="SAMPLE-AddRetentionConfig-Parent-ModalID">@ViewData["ModalID"]</label>
        </div>
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">名称*</span>
        </div>
        <div class="col-9 pl-0">
            <input id="SAMPLE-AddRetentionConfig-Name" class="form-control font-rfs border-radius-noleft" placeholder="必填" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">包装数量</span>
        </div>
        <div class="col-9 pl-0 input-group">
            <input id="SAMPLE-AddRetentionConfig-ContainerNumber" class="form-control font-rfs border-radius-noleft" style="width:30%" placeholder="整数" maxlength="2" onkeyup="value=value.replace(/[^\d]/g,'')" />
            <span class="input-group-text font-rfs border-radius-noradius noRightBorder noLeftBorder" style="width:30%">包装</span>
            <div class="input-group" style="width:40%">
                <select id="SAMPLE-AddRetentionConfig-Select-Container" class="form-control font-rfs border-radius-noleft" style="width:40%"></select>
                <div class="col-11 pl-0 input-group position-absolute float-left">
                    <input id="SAMPLE-AddRetentionConfig-Input-Container" class="form-control font-rfs border-radius-noleft noRightBorder" style="width:100%" placeholder="可输入" />
                </div>
            </div>
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">留样数量</span>
        </div>
        <div class="col-9 pl-0 input-group">
            <input id="SAMPLE-AddRetentionConfig-Quantity" class="form-control font-rfs border-radius-noleft" style="width:30%" />
            <span class="input-group-text font-rfs border-radius-noradius noRightBorder noLeftBorder" style="width:30%">数量单位</span>
            <div class="input-group" style="width:40%">
                <select id="SAMPLE-AddRetentionConfig-Select-Unit" class="form-control font-rfs border-radius-noleft" style="width:40%"></select>
                <div class="col-11 pl-0 input-group position-absolute float-left">
                    <input id="SAMPLE-AddRetentionConfig-Input-Unit" class="form-control font-rfs border-radius-noleft noRightBorder" style="width:100%" placeholder="可输入" />
                </div>
            </div>
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">留样时长</span>
        </div>
        <div class="col-9 pl-0 input-group">
            <input id="SAMPLE-AddRetentionConfig-Duration" class="form-control font-rfs border-radius-noleft" style="width:30%" placeholder="整数" maxlength="2" onkeyup="value=value.replace(/[^\d]/g,'')" />
            <span class="input-group-text font-rfs border-radius-noradius noRightBorder noLeftBorder" style="width:30%">时长单位</span>
            <select id="SAMPLE-AddRetentionConfig-DurationUnit" class="form-control font-rfs border-radius-noleft" style="width:40%">
                <option>日</option>
                <option>月</option>
                <option>年</option>
            </select>
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">到期提醒</span>
        </div>
        <div class="col-9 pl-0">
            <input id="SAMPLE-AddRetentionConfig-Remind" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">存储位置</span>
        </div>
        <div class="col-9 pl-0 input-group">
            <select id="SAMPLE-AddRetentionConfig-Position" class="form-control font-rfs border-radius-noleft"></select>
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">存储条件</span>
        </div>
        <div class="col-9 pl-0 input-group">
            <select id="SAMPLE-AddRetentionConfig-StorageConditions" class="form-control font-rfs border-radius-noleft" style="width:90%"></select>
            <button id="SAMPLE-AddRetentionConfig-AddConditions" class="input-group-text font-rfs border-radius-noleft noLeftBorder pl-2" style="width:10%" title="选择存储条件"><i class="bi-plus"></i></button>
        </div>
    </div>
    <div class="text-right">
        <button id="Supplier-AddRetentionConfig-confirm" class="btn btn-primary font-rfs">确定</button>
        <button id="Supplier-AddRetentionConfig-cancel" type="button" class="btn btn-info font-rfs">取消</button>
    </div>
</div>
    <div class="modal" id="SAMPLE-AddRetentionConfig-AddUnits-Modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p id="SAMPLE-AddRetentionConfig-AddUnits-modalTitle" class="pt-3 pl-3"></p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
                <label id="ModalID" style="display:none">SAMPLE-AddRetentionConfig-AddUnits-Modal</label>
            </div>
            <div class="modal-body">
                <div id="SAMPLE-AddRetentionConfig-AddUnits-Embed"></div>
            </div>
        </div>
    </div>
</div>

<script>

    $(document).ready(function () {
        LoadRetentionConfig()
        LoadContainer();
        LoadUnit();
        GetLocationList('SAMPLE-AddRetentionConfig-Position', '留样');
    });

    function LoadContainer() {
        $.post("GetRetentionConfigContainer", {
        }, function (data) {
            for (var i = 0; i < data.length; i++) {
                $("#SAMPLE-AddRetentionConfig-Select-Container").append(new Option(data[i].container));
            }
            $("#SAMPLE-AddRetentionConfig-Select-Container").prepend(new Option("", ""));
            $("#SAMPLE-AddRetentionConfig-Select-Container").val("");
        });
    }

    function LoadUnit() {
        $.post("GetRetentionConfigUnit", {
        }, function (data) {
            for (var i = 0; i < data.length; i++) {
                $("#SAMPLE-AddRetentionConfig-Select-Unit").append(new Option(data[i].unit));
            }
            $("#SAMPLE-AddRetentionConfig-Select-Unit").prepend(new Option("", ""));
            $("#SAMPLE-AddRetentionConfig-Select-Unit").val("");
        });
    }

    function LoadRetentionConfig() {
        if (!$("#SAMPLE-AddRetentionConfig-RetentionConfigId").html()) {
            return;
        }
        $.post("GetRetentionConfig", {
            Id: $("#SAMPLE-AddRetentionConfig-RetentionConfigId").html()
        }, function (datas) {
            if (datas) {
                $("#SAMPLE-AddRetentionConfig-Name").val(datas.name);
                $("#SAMPLE-AddRetentionConfig-ContainerNumber").val(datas.containerNumber);
                $("#SAMPLE-AddRetentionConfig-Input-Container").val(datas.container);
                $("#SAMPLE-AddRetentionConfig-Quantity").val(datas.quantity);
                $("#SAMPLE-AddRetentionConfig-Input-Unit").val(datas.unit);
                $("#SAMPLE-AddRetentionConfig-Duration").val(datas.duration);
                $("#SAMPLE-AddRetentionConfig-DurationUnit").val(datas.durationUnit);
                $("#SAMPLE-AddRetentionConfig-Remind").val(datas.remind);
            }
        });
    }

    $("#SAMPLE-AddRetentionConfig-Select-Container").change(function () {
        $("#SAMPLE-AddRetentionConfig-Input-Container").val($("#SAMPLE-AddRetentionConfig-Select-Container").find("option:selected").text());
    });

    $("#SAMPLE-AddRetentionConfig-Select-Unit").change(function () {
        $("#SAMPLE-AddRetentionConfig-Input-Unit").val($("#SAMPLE-AddRetentionConfig-Select-Unit").find("option:selected").text());
    });

    $("#Supplier-AddRetentionConfig-confirm").click(function () {
        if ($.trim($("#SAMPLE-AddRetentionConfig-Name").val()).length == 0) {
            alert("名称不能为空！");
            $("#SAMPLE-AddRetentionConfig-Name").addClass('error-style');
            return;
        }

        var Quantity = $.trim($("#SAMPLE-AddRetentionConfig-Quantity").val());
        if (!$.isNumeric(Quantity)) {
            alert("留存样品数量必需是数值！");
            $("#SAMPLE-AddRetentionConfig-Quantity").addClass('error-style');
            return;
        }

        var jsonStr = {};
        jsonStr["Name"] = $.trim($("#SAMPLE-AddRetentionConfig-Name").val());
        jsonStr["ContainerNumber"] = $.trim($("#SAMPLE-AddRetentionConfig-ContainerNumber").val());
        jsonStr["Container"] = $.trim($("#SAMPLE-AddRetentionConfig-Input-Container").val());
        jsonStr["Quantity"] = Quantity;
        jsonStr["Unit"] = $.trim($("#SAMPLE-AddRetentionConfig-Input-Unit").val());
        jsonStr["Duration"] = $.trim($("#SAMPLE-AddRetentionConfig-Duration").val());
        jsonStr["DurationUnit"] = $.trim($("#SAMPLE-AddRetentionConfig-DurationUnit").find("option:selected").text());
        jsonStr["Remind"] = $.trim($("#SAMPLE-AddRetentionConfig-Remind").val());
        jsonStr["Position"] = $.trim($("#SAMPLE-AddRetentionConfig-Position").val());
        jsonStr["StorageConditions"] = $("#SAMPLE-AddRetentionConfig-StorageConditions").val();

        if ($("#SAMPLE-AddRetentionConfig-RetentionConfigId").html() == "") {
            $.post("postAddRetentionConfig", {
                jsonStr: JSON.stringify(jsonStr)
            }, function (data) {
                alert(data);
            });
        } else {
            jsonStr["Id"] = $("#SAMPLE-AddRetentionConfig-RetentionConfigId").html();
            $.post("UpdateRetentionConfig", {
                jsonStr: JSON.stringify(jsonStr)
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    var modalID = $("#SAMPLE-AddRetentionConfig-Parent-ModalID").html();
                    $("#" + modalID).modal('hide');
                } else {
                    alert(data);
                }
            });
        }

    });

    $("#Supplier-AddRetentionConfig-cancel").click(function () {
        var modalID = $("#SAMPLE-AddRetentionConfig-Parent-ModalID").html();
        $("#" + modalID).modal('hide');
    });

</script>
